package gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;

import types.DEPT_TYPES;
import user.User;
import javax.swing.JSplitPane;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JScrollPane;
import java.awt.Dimension;

public class StudentCourseSelect extends JFrame {

	private JPanel contentPane;
	private User currUser;
	private JSplitPane splitPane;
	private JButton backBttn;
	private JPanel panel;
	private JButton registerBttn;
	private JLabel termLabel;
	private JLabel deptLabel;
	private JScrollPane scrollPane;
	private JPanel panel_1;
	private JLabel selectLabel;
	private JLabel crnLabel;
	private JLabel titleLabel;
	private JLabel sectionLabel;
	private JLabel daysLabel;
	private JLabel instLabel;
	private JLabel timeLabel;
	private JLabel locLabel;
	private JLabel gModeLabel;
	private JPanel selectPanel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StudentCourseSelect frame = new StudentCourseSelect(new User("stud1"), DEPT_TYPES.BME);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	//----------------------------------------------------------------------------------------------------------------
	
	/**
	 * Create the frame.
	 */
	public StudentCourseSelect(User currUser, DEPT_TYPES deptSelect) {
		this.currUser = currUser;
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		splitPane = new JSplitPane();
		contentPane.add(splitPane, BorderLayout.SOUTH);
		
		registerBttn = new JButton("Register");
		splitPane.setRightComponent(registerBttn);
		registerBttn.addActionListener(nextListener);
		
		backBttn = new JButton("Back");
		splitPane.setLeftComponent(backBttn);
		backBttn.addActionListener(cancelListener);
		
		panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		panel.setLayout(new GridLayout(0, 2, 0, 0));
		
		termLabel = new JLabel("Term: ");
		panel.add(termLabel);
		
		deptLabel = new JLabel("Dept: " + deptSelect.toString());
		panel.add(deptLabel);
		
		
		
		panel_1 = new JPanel();
		panel_1.setSize(new Dimension(50, 50));

		panel_1.setLayout(new GridLayout(1, 10, 0, 0));
		
		JRadioButton form[][] = new JRadioButton[12][8];
	    String counts[] = { "Select", "CRN", "Title", "Course Code", "Instructor", "Days", "Time", "Location", "Mode of Grading" };
	    String categories[] = { "Household", "Office", "Extended Family",
	        "Company (US)", "Company (World)", "Team", "Will",
	        "Birthday Card List", "High School", "Country", "Continent",
	        "Planet" };
	    JPanel p = new JPanel();
	    p.setSize(600, 400);
	    p.setLayout(new GridLayout(13, 9, 10, 0));
	    for (int row = 0; row < 13; row++) {
	      ButtonGroup bg = new ButtonGroup();
	      for (int col = 0; col < 9; col++) {
	        if (row == 0) {
	          p.add(new JLabel(counts[col]));
	        } 
	        else {
	          if (col == 0) {
	        	  //p.add(new JLabel(categories[row - 1]));
	          } 
	          else {
	        	  /*
	            form[row - 1][col - 1] = new JRadioButton();
	            bg.add(form[row - 1][col - 1]);
	            p.add(form[row - 1][col - 1]);
	            */
	          }
	        }
	      }
	    }
	    scrollPane = new JScrollPane(p);
		contentPane.add(scrollPane, BorderLayout.CENTER);
		
		//scrollPane.add(panel_1);
	
		
	}
	//------------------------------------------------------------------------------------------------
	
	private void addRowToCourseList() {
		
	}
	
	
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BUTTON LISTENERS
///////////////////////////////////////////////////////////////////////////////////////////////////////

	private ActionListener nextListener = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			StudentRegComp regFrame = new StudentRegComp(currUser);
			regFrame.setVisible(true);
			StudentCourseSelect.this.dispose();
		}
	};
	//------------------------------------------------------------------------------------------------
	
	private ActionListener cancelListener = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			StudentDeptSelect regFrame = new StudentDeptSelect(currUser);
			regFrame.setVisible(true);
			StudentCourseSelect.this.dispose();
		}
	};
	//------------------------------------------------------------------------------------------------
}
